package com.jdz.gxq.info.admin.envinfo.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jdz.gxq.info.admin.envinfo.bo.Envinfo;
import com.jdz.gxq.info.admin.envinfo.form.EnvinfoListForm;
import com.jdz.gxq.info.admin.envinfo.service.EnvinfoService;
import com.jdz.gxq.info.common.action.CommonAction;
import com.jdz.gxq.info.common.bo.PageBean;

public class EnvinfoListAction extends CommonAction {

	private EnvinfoService envinfoService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		EnvinfoListForm envinfoListForm = (EnvinfoListForm) form;
		
		String enterpriseName = envinfoListForm.getEnterpriseName();

		int totalCount = envinfoService.getEnvinfosCount(enterpriseName);
		
		int currentPage = envinfoListForm.getPageIndex();

		PageBean pageBean = new PageBean(totalCount, currentPage);
		
		envinfoListForm.setPageIndex(pageBean.getCurrentPage());
		
		Map<String, Object> params = new HashMap<String, Object>();
		
		// 分页用
		params.put("startRow", pageBean.getPageStartRow() - 1);
		params.put("rowSize", pageBean.getPageSize());
		params.put("enterpriseName", enterpriseName);
		
		List<Envinfo> envinfoList = envinfoService.getEnvinfos(params);
		
		request.setAttribute("envinfoList", envinfoList);
		request.setAttribute("pageBean", pageBean);
		
		return mapping.findForward("success");
	}

	public void setEnvinfoService(EnvinfoService envinfoService) {
		this.envinfoService = envinfoService;
	}
}

